package com.gaga.controller;

import com.gaga.pojo.SysUser;
import com.gaga.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
class LoginController{

    @Resource
    private UserService userService;

    @RequestMapping(value = "/login")
    public String login(String usrName, String usrPassword, Model model, HttpSession session){
        System.out.println("login " + usrName + " " + usrPassword);
        SysUser user = userService.login(usrName,usrPassword);
        System.out.println(user);
        if(user!=null){
            session.setAttribute("loginUser",user);
            return "redirect:/main";
        }else{
            model.addAttribute("msg","用户名或密码错误，登录失败！");
            return "forward:/login.jsp";
        }
    }

    @RequestMapping(value = "/main")
    public String main(){
        return "main";
    }
}
